package simplescenegraph.math;

public class Vector3f {
	
	public static final Vector3f X_AXIS = new Vector3f(1, 0, 0);
	
	public static final Vector3f Y_AXIS = new Vector3f(0, 1, 0);
	
	public static final Vector3f Z_AXIS = new Vector3f(0, 0, -1);
	
	public float x, y, z;
	
	float[] xyz;
	
	public float getX() {
		return x;
	}
	
	public void setX(float x) {
		this.x = x;
	}
	
	public float getY() {
		return y;
	}
	
	public void setY(float y) {
		this.y = y;
	}
	
	public float getZ() {
		return z;
	}
	
	public void setZ(float z) {
		this.z = z;
	}
	
	public Vector3f() {
		x = 0;
		y = 0;
		z = 0;
	}
	
	public Vector3f(float x, float y, float z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	public Vector3f(Vector3f arg0) {
		this(arg0.x, arg0.y, arg0.z);
	}
	
	public Vector3f(Vector3f p0, Vector3f p1) {
		this(p1.x - p0.x, p1.y - p0.y, p1.z - p0.z);
	}
	
	public void add(Vector3f arg0) {
		this.x += arg0.x;
		this.y += arg0.y;
		this.z += arg0.z;
	}
	
	public void subtract(Vector3f arg0) {
		this.x -= arg0.x;
		this.y -= arg0.y;
		this.z -= arg0.z;
	}
	
	public void multiply(float a) {
		this.x *= a;
		this.y *= a;
		this.z *= a;
	}
	
	public void divide(float a) {
		this.x /= a;
		this.y /= a;
		this.z /= a;
	}
	
	public float dotProduct(Vector3f arg0) {
		return x * arg0.x + y * arg0.y + z * arg0.z;
	}
	
	public Vector3f projection(Vector3f q) {
		Vector3f projQP = new Vector3f(q);
		projQP.multiply((dotProduct(q) / q.squaredLength()));
		return projQP;
	}
	
	public float squaredLength() {
		return x * x + y * y + z * z;
	}
	
	public float length() {
		return (float) Math.sqrt(x * x + y * y + z * z);
	}
	
	public void normalize() {
		float l0 = length();
		if (l0 > 0) {
			x /= l0;
			y /= l0;
			z /= l0;
		}
	}
	
	public void multiply(Matrix3f arg0) {
		float x0 = x, y0 = y, z0 = z;
		x = arg0.m[0] * x0 + arg0.m[1] * y0 + arg0.m[2] * z0;
		y = arg0.m[3] * x0 + arg0.m[4] * y0 + arg0.m[5] * z0;
		z = arg0.m[6] * x0 + arg0.m[7] * y0 + arg0.m[8] * z0;
	}
	
	public boolean equals(Object obj0) {
		Vector3f v0 = (Vector3f) obj0;
		return x == v0.x && y == v0.y && z == v0.z;
	}
	
	public String toString() {
		return "|" + x + "|\n|" + y + "|\n|" + z + '|';
	}
	
	public float[] toFloatArray() {
		if (xyz == null) xyz = new float[3];
		xyz[0] = x; xyz[1] = y; xyz[2] = z;
		return xyz;
	}
	
}
